﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PMSA.Framework.Log;

public partial class Admin_Uc_Product_GroupProductManager : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            CreateDDLGroupProductParent();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        try
        {
            GroupProduct obj = new GroupProduct();
            int active = txtGroupProductActive.Checked ? 1 : 0;
            int groupParent = int.Parse(ddlGroupProductParent.SelectedValue);
            int status = int.Parse(txtStatus.Text);
            obj.Insert(txtGroupProductName.Text, active, groupParent, status);
        }
        catch (Exception ex)
        {
            CLogManager.Write("GroupProduct.Manager.btnAdd_Click", ex.ToString(), "ADMIN");
        }
    }
    private void CreateDDLGroupProductParent()
    {
        try
        {
            GroupProductLevelParent obj = new GroupProductLevelParent();
            IList<GroupProductLevelParent> list = obj.List(0);
            ddlGroupProductParent.DataValueField = "Id";
            ddlGroupProductParent.DataTextField = "Name";
            ddlGroupProductParent.DataSource = list;
            ddlGroupProductParent.DataBind();
        }
        catch (Exception ex)
        {
            CLogManager.Write("Product.Edit.CreateDDLGroupProductParent", ex.ToString(), "ERR");
        }
    }
}